package main;

import java.text.DecimalFormat;
import java.util.Arrays;

import util.Dice;
import util.StatPotential;
import util.UtilMath;
import data.obj.Stats;

public class StatGenerator
{
	protected double[][] stats=new double[2][10];
	private double tempTreshold;
	private double potTreshold;
	
	public StatGenerator(double tempTreshold, double potTreshold)
    {
		this.tempTreshold=tempTreshold;
		this.potTreshold=potTreshold;
		
    }

	public StatGenerator()
    {
		this.tempTreshold=0;
		this.potTreshold=0;
		
    }

	public static void main(String[] args) throws Exception
    {
		double tempTreshold = 60;
		double potTreshold = 97;
		StatGenerator statGenerator = new StatGenerator( tempTreshold,  potTreshold);
		statGenerator.process();
		
		double[][] stats = statGenerator.getStats();
		
		int index=0;
		for(Stats s : Stats.values()){
			System.out.println(s+"\t"+stats[0][index]+"\t"+stats[1][index++]);
		}
		System.out.println("mean: \t"+UtilMath.mean(stats[0])+"\t"+UtilMath.mean(stats[1]));
		
    }

	private double[][] getStats()
    {
	    return stats;
    }

	private void process() throws Exception
    {

		DecimalFormat df2 = new DecimalFormat( "#,###,###,##0" );

	    StatPotential sp= new StatPotential();
	    
	    double[] temp = new double[10];
	    double[] pot = new double[10];
	    boolean tempOk=false;
	    boolean potOk=false;
	    int tempt=0;
	    do
        {
	    	if(tempt%10000==0)
	    	    System.out.println("Pot: "+tempt);
	    	
	        for(int i=0;i<10;i++)
	        	temp[i]=Dice.D100(32);
	        Arrays.sort(temp);
	        if(temp[0]<90)
	        	temp[0]=90;
	        if(temp[1]<90)
	        	temp[1]=90;
	        double mean =  UtilMath.mean(temp);
	        if (mean>=tempTreshold){
	        	tempOk=true;
	        	System.out.println("Temp: "+df2.format(tempt)+ " mean:"+ mean);
	        	
	        }
	        tempt++;
	        
        } while (!tempOk);
	    
	    
	    tempt=0;
	    do
        {
	    	if(tempt%1000000==0)
	    	    System.out.println("Temp: "+df2.format(tempt));
	    	
	        for(int i=0;i<10;i++)
	        	pot[i]=sp.getValue(Dice.D100(), temp[i]);
	      
	        double mean =  UtilMath.mean(pot);
	        if (mean>=potTreshold){
	        	potOk=true;
	        	System.out.println("Temp: "+df2.format(tempt)+ " mean:"+ mean);
	        }
	       tempt++;
	        
        } while (!potOk);

	    stats[0]=temp;
	    stats[1]=pot;
	    
    }
}
